// pages/search/search.js

const library = require ('./library.js')
const oneClass = require ('./oneClass.js')
const twoClass = require ('./twoClass.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    objectMultiArray: [
      // 周
      [
        {id: 1,name: '第1周'},
        {id: 2,name: '第2周'},
        {id: 3,name: '第3周'},
        {id: 4,name: '第4周'},
        {id: 5,name: '第5周'},
        {id: 6,name: '第6周'},
        {id: 7,name: '第7周'},
        {id: 8,name: '第8周'},
        {id: 9,name: '第9周'},
        {id: 10,name: '第10周'},
        {id: 11,name: '第11周'},
        {id: 12,name: '第12周'},
        {id: 13,name: '第13周'},
        {id: 14,name: '第14周'},
        {id: 15,name: '第15周'},
        {id: 16,name: '第16周'},
        {id: 17,name: '第17周'},
        {id: 18,name: '第18周'},
        {id: 19,name: '第19周'},
        {id: 20,name: '第20周'},
      ], 
      // 星期
      [
        {id: 1,name: '星期一'},
        {id: 2,name: '星期二'},
        {id: 3,name: '星期三'},
        {id: 4,name: '星期四'},
        {id: 5,name: '星期五'},
        {id: 6,name: '星期六'},
        {id: 7,name: '星期天'},
      ],
    ],
    multiIndex2: [0, 0],
  },

  bindMultiPickerChange2: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      multiIndex2: e.detail.value
    })
  },

  selectClass: function(e) { 
    console.log(e.currentTarget.dataset.item)
    var room = e.currentTarget.dataset.item
    var week = this.data.objectMultiArray[0][this.data.multiIndex2[0]].name
    var day = this.data.objectMultiArray[1][this.data.multiIndex2[1]].name
    var courses = room.courses
    var tip = ["无"]
    courses.forEach(element => {
      var day1 = element.day
        // 判断星期几
        if (day1 == day) {
          var week1 = element.week
          week1.forEach(item => {
            // 判断第几周
            if (item == week) {
              tip = element.hour
              console.log("————————————————————————————————————————————————————"+tip)
            }
          });
        }
      });

    wx.showModal({
      title: room.name,
      content: "当日有课时段："+tip,
      showCancel: false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      library: library.library,
      oneClass: oneClass.oneClass,
      twoClass: twoClass.twoClass
    })
    console.log("成功")
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})